﻿Imports System.Data.SqlClient

Public Class TaiKhoanDAO
    Public Shared Function LoaiTaiKhoan() As DataTable
        Dim strSQL As String = "usp_LoaiTaiKhoan"
        Dim dt As New DataTable
        dt = DataProvider.LoadTable(strSQL)
        Return dt
    End Function

    Public Shared Function DangKiTK(ByVal tkDTO As TaiKhoanDTO) As Integer
        Dim strSQL As String = "usp_DangKiTK"
        Dim cn As SqlConnection = DataProvider.GetCn()
        Dim cmd As New SqlCommand(strSQL, cn)
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@TenDangNhap", SqlDbType.VarChar)
        cmd.Parameters.Add("@MatKhau", SqlDbType.VarChar)
        cmd.Parameters.Add("@MaLTK", SqlDbType.VarChar)
        cmd.Parameters.Add("@out", SqlDbType.Int).Direction = ParameterDirection.Output

        cmd.Parameters("@TenDangNhap").Value = tkDTO.m_strTenDangNhap
        cmd.Parameters("@MatKhau").Value = tkDTO.m_strMatKhau
        cmd.Parameters("@MaLTK").Value = tkDTO.m_strMaLoaiTK

        cmd.ExecuteNonQuery()
        cn.Close()
        Dim a As Integer = cmd.Parameters("@out").Value
        Return a
    End Function

    Public Shared Function KTDangNhap(ByVal tkDTO As TaiKhoanDTO) As Integer
        Dim strSQL As String = "usp_KTDangNhap"
        Dim cn As SqlConnection = DataProvider.GetCn()
        Dim cmd As New SqlCommand(strSQL, cn)
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@TenDangNhap", SqlDbType.VarChar)
        cmd.Parameters.Add("@MatKhau", SqlDbType.VarChar)
        cmd.Parameters.Add("@out", SqlDbType.Int).Direction = ParameterDirection.Output

        cmd.Parameters("@TenDangNhap").Value = tkDTO.m_strTenDangNhap
        cmd.Parameters("@MatKhau").Value = tkDTO.m_strMatKhau

        cmd.ExecuteNonQuery()
        cn.Close()
        Dim a As Integer = cmd.Parameters("@out").Value
        Return a
    End Function
End Class
